#!/usr/bin/env python
# encoding: utf-8
"""
common.py

Created by 刘 智勇 on 2011-05-03.
Copyright (c) 2011 __MyCompanyName__. All rights reserved.
"""

#!/usr/bin/env python
# encoding: utf-8
"""
common.py

Created by 刘 智勇 on 2011-05-03.
Copyright (c) 2011 __MyCompanyName__. All rights reserved.
"""

import logging
from tornado.web import RequestHandler

from tornadomongodb.configure import DB_CON
from tools import session


class BaseHandler(RequestHandler):
    @property
    def db(self):
        return DB_CON
        
    @property
    def cache(self):
        return self.settings["cache_engine"]
        
    def get_current_user(self):
        return self.get_secure_cookie("user")
        
    def render(self, template_name, **kwargs):
        if 'warning' not in kwargs.keys():
            kwargs['warning'] = None
        super(BaseHandler, self).render(template_name, **kwargs)
        

class RootHandler(BaseHandler):
    @session
    def get(self):
        self.write("index.html")

class MainHandler(BaseHandler):
    def get(self):
        self.write("main.html")

class TestHandler(BaseHandler):
    @session
    def get(self, page):
        html = page+".html"
        self.render(html)

class Error404Handler(BaseHandler):
    def get(self):
        self.write("404")

    